subroutine symabcaab2(iabc, ibca, iout, popina, popinb, irrepabc)
use mod_iop
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout)::iabc(*), ibca(*), iout(*)
if(prec==8.and.igpu==0) then 
  call symabcaab2_d(iabc, ibca, iout, popina, popinb, irrepabc)
elseif(prec==4.and.igpu==0) then 
  call symabcaab2_s(iabc, ibca, iout, popina, popinb, irrepabc)
elseif(prec==8.and.igpu==1) then 
  call symabcaab2_dg(iabc, ibca, iout, popina, popinb, irrepabc)
elseif(prec==4.and.igpu==1) then 
  call symabcaab2_sg(iabc, ibca, iout, popina, popinb, irrepabc)
endif
!
return
end
subroutine symabcaab2_d(iabc, ibca, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout)::iabc(*), ibca(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca, npop23(8), numabin, idxabcin
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba, ioffabcin
! a<b,c = abc + bca -acb 
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
   npop23(irrep) = irpdso(irrep, popina, popina, 1)
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   numabin = irpdso(irrepab, popina, popina, 1)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb 
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffabcin = isymoffso(irrepc, irrepabc, npop23, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 1) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 2, numb 
          do a = 1, b-1
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$omp end parallel do
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 1, numb 
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$omp end parallel do
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab2_s(iabc, ibca, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*4, intent(inout)::iabc(*), ibca(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca, npop23(8), numabin, idxabcin
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba, ioffabcin
! a<b,c = abc + bca -acb 
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
   npop23(irrep) = irpdso(irrep, popina, popina, 1)
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   numabin = irpdso(irrepab, popina, popina, 1)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb 
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffabcin = isymoffso(irrepc, irrepabc, npop23, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 1) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 2, numb 
          do a = 1, b-1
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$omp end parallel do
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$omp parallel do
          do c = 1, numc 
          do b = 1, numb 
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$omp end parallel do
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab2_dg(iabc, ibca, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*8, intent(inout),device::iabc(*), ibca(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca, npop23(8), numabin, idxabcin
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba, ioffabcin
! a<b,c = abc + bca -acb 
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
   npop23(irrep) = irpdso(irrep, popina, popina, 1)
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   numabin = irpdso(irrepab, popina, popina, 1)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb 
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffabcin = isymoffso(irrepc, irrepabc, npop23, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 1) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 2, numb 
!$acc loop independent
          do a = 1, b-1
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$acc end kernels
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 1, numb 
!$acc loop independent
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$acc end kernels
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
subroutine symabcaab2_sg(iabc, ibca, iout, popina, popinb, irrepabc)
use mod_symm
use mod_orbit
use mod_t
implicit none
integer, intent(in) :: popina(8), popinb(8), irrepabc
real*4, intent(inout),device::iabc(*), ibca(*), iout(*)
integer, external :: irpdso, isymoffso, idsymabc, isymoffabc
integer irrepa, irrepb, irrepc, irrepab, irrepbc, irrepca
integer idxabc, idxbc, idxcab, idxout, npop2(8), npop22(8)
integer ioffabc, ioffbca, ioffcab, ioffout, idxtest
integer irrep, numa, numb, numc, a, b, c, idxbca
integer numab, numbc, numca, npop23(8), numabin, idxabcin
integer irrepac, irrepcb, numcb, numac, ioffacb, ioffcba
integer idxacb, idxcba, ioffabcin
! a<b,c = abc + bca -acb 
do irrep = 1, nirrep 
   npop2(irrep) = irpdso(irrep, popina, popina, 0)
   npop22(irrep) = irpdso(irrep, popina, popinb, 1) 
   npop23(irrep) = irpdso(irrep, popina, popina, 1)
enddo 
!
idxtest =0
do irrepc = 1, nirrep 
   irrepab = dirprd(irrepc, irrepabc) 
   numab = irpdso(irrepab, popina, popina, 0)
   numabin = irpdso(irrepab, popina, popina, 1)
   do irrepb = 1, nirrep 
      irrepa = dirprd(irrepb, irrepab)
      irrepbc = dirprd(irrepb, irrepc) 
      irrepca = dirprd(irrepc, irrepa)
      irrepac = irrepca
      irrepcb = irrepbc
      numbc = irpdso(irrepbc, popina, popinb, 1)
      numca = irpdso(irrepca, popina, popinb, 1)
      numcb = numbc 
      numac = numca
      numa = popina(irrepa)
      numb = popina(irrepb)
      numc = popinb(irrepc) 
! a<b,c = abc + bca -acb 
      ioffabc = isymoffso(irrepc, irrepabc, npop2, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 0) - 1  
      ioffabcin = isymoffso(irrepc, irrepabc, npop23, popinb, 1) - 1 &
              + isymoffso(irrepb, irrepab, popina, popina, 1) - 1  
      ioffbca = isymoffso(irrepa, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepbc, popina, popinb, 1) - 1  
      ioffacb = isymoffso(irrepb, irrepabc, npop22, popina, 1) - 1 &
              + isymoffso(irrepc, irrepac, popina, popinb, 1) - 1  
      if(irrepa>irrepb) cycle
      if(irrepa==irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 2, numb 
!$acc loop independent
          do a = 1, b-1
             idxabc = ioffabc + (c-1)*numab + (b-1)*(b-2)/2 + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$acc end kernels
!          write(6,'(A,i4,i4,i4,i4)')'idxtest', idxtest, irrepa, irrepb, irrepc
      elseif(irrepa<irrepb) then 
!$acc kernels 
!$acc loop independent
          do c = 1, numc 
!$acc loop independent
          do b = 1, numb 
!$acc loop independent
          do a = 1, numa 
             idxabc = ioffabc + (c-1)*numab + (b-1)*numa + a 
             idxabcin = ioffabcin + (c-1)*numabin + (b-1)*numa + a 
             idxbca = ioffbca + (a-1)*numbc + (c-1)*numb + b 
             idxacb = ioffacb + (b-1)*numac + (c-1)*numa + a 
!             write(6,'(A, I4, I4, I4, I4, I4)')'idxabc', idxabc, a, b, c, ioffabc
             iout(idxabc) = iabc(idxabcin) + ibca(idxbca) - ibca(idxacb) 
!             write(6,*)'idxabc', ioffabc, idxabc 
          enddo
          enddo
          enddo 
!$acc end kernels
       endif
    enddo
enddo
!write(6,*)'idxtest', idxtest
return
end
